from django import template
from django.template.defaultfilters import stringfilter

from decimal import Decimal

register = template.Library()


@register.filter
@stringfilter
def model_format(value, arg):
	if value == 'N/A' or arg == 'N/A':
		return value
	return value.replace(arg, '')

@register.filter
@stringfilter
def exposure_time_format(value):
	if value == 'N/A':
		return value
	return  value + ' sec.'

@register.filter
@stringfilter
def aperture_format(value):
	if value == 'N/A' or value.find('/') == -1:
		return value
	a,b = value.split('/')
	c = Decimal(a) / Decimal(b)
	return 'f/' + str(c)

@register.filter
@stringfilter
def focal_length_format(value):
	if value == 'N/A' or value.find('/') == -1:
		return value
	a,b = value.split('/')
	c = Decimal(a) / Decimal(b)
	return  str(c) + 'mm'